<?php
/**
 * @file name : utility_helper.php
 * @package   :
 * @author    : Vo Thanh Minh
 * @email     : <thanhminhld@yahoo.com - thanhminhld@gmail.com>
 * @copyright : 2011
 *
 */
if (!defined('BASEPATH')) {
    exit('No direct script access');
}
/**
 * defaultPage
 *
 * This function will be redirect to control name
 * It only use when 'enable_query_strings' = true in config.php file
 */
if ( ! function_exists('defaultPage')) {
    function defaultPage($controlName)
    {
        if (!is_string($controlName)) {
            return false;
        }
        header("Location:?c=" . $controlName);
    }
}
/**
 * replaceSpecialChar
 *
 * @param string
 * This function will replace all character not alpha and _
 */
if ( ! function_exists('replaceSpecialChar')) {
    function replaceSpecialChar($str)
    {
        if (strlen($str) <= 0) {
            return $str;
        }
        $str = preg_replace('/[^a-zA-Z0-9_]/', '', $str);
        return $str;
    }
}
/**
 *
 *
 *
 */
if ( ! function_exists('arrayFilter')) {
    function arrayFilter($delimiter, $array)
    {
        $arrReturn = array();
        if (is_string($array)) {
            $key = substr($array, 0, strpos($array, $delimiter));
            $val = substr($array, strpos($array, $delimiter));
            $arrReturn = array($key => $val);

            return $arrReturn;
        }
        if (is_array($array)) {
            $arrChange = array();
            foreach ($array as $pKey => $value) {
                $tmpArr = explode($delimiter, $value);
                if (array_key_exists('1', $tmpArr)) {
                    $arrChange[$tmpArr[0]] = $tmpArr[1];
                } else {
                    $arrChange[$tmpArr[0]] = '';
                }
            }
            $arrReturn = $arrChange;
        }
        return $arrReturn;
    }
}